package designpattern.demo.creational.prototypepattern;

import java.util.ArrayList;

public class Thing implements Cloneable {
    //定义一个私有变量
    private ArrayList<String> arrayList = new ArrayList<String>();

    @Override
    public Thing clone() {
        Thing thing = null;
        try {
            thing = (Thing) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return thing;
    }

    //设置HashMap的值
    public void setValue(String value) {
        this.arrayList.add(value);
    }

    //取得arrayList的值
    public ArrayList<String> getValue() {
        return this.arrayList;
    }
}

////测试类
// class Client {
//    public static void main(String[] args) {
//        //产生一个对象
//        Thing thing = new Thing();
//        //设置一个值
//        thing.setValue("张三");
//        //拷贝一个对象
//        Thing cloneThing = thing.clone();
//        cloneThing.setValue("李四");
//        System.out.println(thing.getValue());
//    }
//}